java如果有人试图访问我的JSP页面,如何首先显示登录页面?
我正在从事Spring MVC控制器项目。我制作了一个JSP页面,这是我的简单UI-
所以,如果我点击这个url-http://localhost:8080/testweb/testOperation
,我可以看到我的JSP页面,一切正常。下面是我在控制器中添加的代码-
@RequestMapping(value = "testOperation", method = RequestMethod.GET)
public Map<String, String> zookOperation() {
final Map<String, String> model = new LinkedHashMap<String, String>();
return model;
}
现在我正在尝试添加一个登录身份验证。我在想,如果任何试图访问这个url http://localhost:8080/testweb/testOperation
的人必须先登录,然后如果它得到验证,那么只显示testOperation
jsp页面的实际内容
我已经创建了login.jsp
页面,但是当有人试图访问这个url http://localhost:8080/testweb/testOperation
时,我如何重定向到login.jsp
页面,然后在验证之后,我应该显示testOperation
jsp页面的实际内容
下面是login.jsp
页面的代码
@RequestMapping(value = "login", method = RequestMethod.GET)
public Map<String, String> login() {
final Map<String, String> model = new LinkedHashMap<String, String>();
return model;
}
无论如何,这是可能的吗?如果是的话,任何例子都会对我有很大帮助。谢谢
我已经有了身份验证逻辑
注意:-我只想对这个testOperation
jsp页面进行登录验证。对于我拥有的其他jsp页面,我不想这样做
# 1 楼答案
一些选择:
使用标准Java API通过容器添加安全性: http://docs.oracle.com/cd/E19226-01/820-7627/bncby/index.html
使用Spring security,并对要保护的页面启用身份验证。 样本:http://www.mkyong.com/tutorials/spring-security-tutorials/
使用ApacheShiro:https://shiro.apache.org/tutorial.html
我通常会使用Spring安全性,并通过xml配置对其进行配置